package com.xnf.ssmweb.service.impl;

import com.xnf.ssmweb.dao.RoleMapper;
import com.xnf.ssmweb.domain.Role;
import com.xnf.ssmweb.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by chendx on 2021/3/30.
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    public List<Role> queryRoles() {
        return roleMapper.findAll();
    }

    public Role queryRoleById(Long id) {
        return roleMapper.findById(id);
    }

    public boolean saveRole(Role role) {
        return roleMapper.save(role) > 0 ? true : false;
    }

    public void savePermissionToRole(String roleId, String[] permissionIds) {
        for (String permissionId : permissionIds){
            roleMapper.savePermissionToRole(Long.parseLong(roleId),Long.parseLong(permissionId));
        }
    }

    public List<Role> findNoRoleList(Long userId) {
        return roleMapper.findNoRoleList(userId);
    }

}
